package com.shixi.shixitraining.shixitraining.ui.tabmine.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.shixi.shixitraining.shixitraining.R;
import com.shixi.shixitraining.shixitraining.base.TabhostBaseFragment;
import com.shixi.shixitraining.shixitraining.http.CallbackImple;
import com.shixi.shixitraining.shixitraining.http.HttpUtil;
import com.shixi.shixitraining.shixitraining.ui.tabmine.adapter.TrainPayAdapter;
import com.shixi.shixitraining.shixitraining.ui.tabmine.entity.TrainPayBean;
import com.shixi.shixitraining.shixitraining.util.ToastUtil;
import com.shixi.shixitraining.shixitraining.util.UserManager;

import java.util.List;

import retrofit2.Call;

import static com.shixi.shixitraining.shixitraining.constant.Constants.PAY;

/**
 * Created by shenyan on 2018/7/26.
 */

public class PayTrainFragment extends TabhostBaseFragment {

    private TextView mNoPay;

    @Override
    protected int getlayoutId() {
        return R.layout.fragment_pay_job;
    }

    @Override
    protected void initPager() {

//
//        List<TestPayBean> data=new ArrayList<>();
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));

//        JobPayAdapter adapter=new JobPayAdapter(getContext(),data, Glide.with(getContext()));
//        mRcView.setAdapter(adapter);

        mNoPay = (TextView) mContentView.findViewById(R.id.tv_nopay);
        String token = UserManager.getInstance().getToken();
        String userId = UserManager.getInstance().getUserId();

        requestJobPay(token,userId);

    }

    private void requestJobPay(String token, String userId) {
        String url=PAY+"&token="+token+"&userId="+userId+"&iscate="+2;

        HttpUtil.getInstance().getApiInterface().trainPay(url).enqueue(new CallbackImple<TrainPayBean>() {
            @Override
            public void onError(Call<TrainPayBean> call, Throwable t) {
                ToastUtil.showShortToast(getContext(),t.getMessage());
            }

            @Override
            public void onSuccess(Call<TrainPayBean> call, TrainPayBean response) {

                if (response.getStatus()==200){

                    if (response.getData()!=null){
                        final List<TrainPayBean.DataBean> data = response.getData();
                        RecyclerView mRcView = (RecyclerView) mContentView.findViewById(R.id.rcview_pay_job);
                        LinearLayoutManager manager=new LinearLayoutManager(getContext());
                        manager.setOrientation(LinearLayoutManager.VERTICAL);
                        mRcView.setLayoutManager(manager);
                        TrainPayAdapter  adapter=new TrainPayAdapter(getContext(),data);
                        mRcView.setAdapter(adapter);
                    }else {
                        ToastUtil.showShortToast(getContext(),"数据为空");
                    }
                }else {
                    mNoPay.setVisibility(View.VISIBLE);
                    ToastUtil.showShortToast(getContext(),"数据加载失败");
                }

            }
        });




    }
}
